home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_13_04 / CHAPMAN2 / CHAPMAN2.ZIP / C_FAILUR.CPP next >
Encoding:
C/C++ Source or Header  |  1994-02-19  |  1.9 KB  |  58 lines

  1. /* c_failur.cpp - counting_failure_handler implementation */
  2.  
  3. /* this is pretty simple stuff - it installs itself into the handler */
  4. /* chain when it's allocated and removes itself when deleted. along */
  5. /* the way it counts error() and warning() messages before passing */
  6. /* them along to the previous handler, which actually prints them. */
  7.  
  8. #include "utils.hpp"
  9. #include "errmgr.hpp"
  10. #include "c_failur.hpp"
  11.  
  12. counting_failure_handler::counting_failure_handler(void)
  13. {
  14.     /* install ourselves as the current handler when we are created. */
  15.  
  16.     error_logged = warn_logged = 0L;
  17.     prev_handler = err_mgr.define_handler(this);
  18.  
  19. }  /* end of counting_failure_handler::counting_failure_handler() */
  20.  
  21. counting_failure_handler::~counting_failure_handler(void)
  22. {
  23.     /* unlink ourselves from the handler chain when we are destroyed. */
  24.     /* ensure no other handler is stacked over us! */
  25.  
  26.     failure_handler *top;
  27.  
  28.     top = err_mgr.restore_handler();
  29.     ASSERT(top == this);
  30.  
  31. }  /* end of counting_failure_handler::~counting_failure_handler() */
  32.  
  33. void counting_failure_handler::fail(const char *fmt,va_list ap)
  34. {
  35.     prev_handler->fail(fmt,ap);         /* just pass it on - we'll exit soon */
  36.  
  37. }  /* end of counting_failure_handler::fail() */
  38.  
  39. void counting_failure_handler::error(const char *fmt,va_list ap)
  40. {
  41.     ++error_logged;                     /* tally problems */
  42.     prev_handler->error(fmt,ap);        /* pass the message on */
  43.  
  44. }  /* end of counting_failure_handler::error() */
  45.  
  46. void counting_failure_handler::warn(const char *fmt,va_list ap)
  47. {
  48.     ++warn_logged;                      /* tally problems */
  49.     prev_handler->warn(fmt,ap);         /* pass the message on */
  50.  
  51. }  /* end of counting_failure_handler::warn() */
  52.  
  53. void counting_failure_handler::post(const char *fmt,va_list ap)
  54. {
  55.     prev_handler->post(fmt,ap);         /* pass the message on */
  56.  
  57. }  /* end of counting_failure_handler::post() */
  58.